package freakin.wify;

import android.net.wifi.ScanResult;

/**
 * Class representing all necessary information about a wifi network. ATTENTION,
 * any value may be null (or -1);
 * 
 * REMEMBER to set variable locationSet to true, if you change latitude and longitude.
 * 
 */
public class Network {

	long id;
	String bssid;
	String ssid;
	String security;
	double latitude;
	double longitude;
	int frequency;
	int level;
	/**
	 * Set this variable to true if you set latitude and longitude. Your life
	 * depends on it.
	 */
	boolean locationSet;
	
	/** If this network has been send to the server, it will be true. **/
	boolean send;
	public boolean open;

	public Network() {
		id = -1;
		bssid = null;
		ssid = null;
		security = null;
		locationSet = false;
		latitude = -1;
		longitude = -1;
		frequency = -1;
		level = -1;
		send = false;
	}

	public Network(ScanResult result) {
		id = -1;
		bssid = result.BSSID;
		locationSet = false;
		latitude = -1;
		longitude = -1;
		security = result.capabilities;
		frequency = result.frequency;
		level = result.level;
		ssid = result.SSID;
		send = false;
	}

	/**
	 * Calculates distance between two networks.
	 * 
	 * @param a
	 * @param b
	 * @return square of the distance (for performance reasons) or -1 if
	 *         couldn't compute.
	 */
	public static double getDistance(Network a, Network b) {
		double dist = -1;

		if (!a.locationSet || !b.locationSet) {
			return -1;
		}

		dist = ((a.latitude - b.latitude) * (a.latitude - b.latitude))
				+ ((a.longitude - b.longitude) * (a.longitude - b.longitude));

		return dist;
	}

}
